/*
 * Copyright (C) <2009>  <Matthew Dickinson>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.pulsarwebdevelopment.concordance.plugins;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;

import com.pulsarwebdevelopment.concordance.ConcordanceTool;

/**
 * Script for compiling a concordance
 * @author Matthew Dickinson
 * Last updated: 8/13/2009
 */
public class Compiler implements Plugin{

	public void go(Object[] args) {
		File inFile = (File) args[0];
		String concTitle = (String) args[1];
		String concDesc = (String) args[2];
		ConcordanceTool con = new ConcordanceTool(new File("")); //TODO fix this
		con.compileConcordance(inFile, concTitle, concDesc);
		return;
		
	}

	public void plug(PluginScreen screen) {
		//isPlugin = true;
		screen.giveFileBrowser(FileBrowser.FileType.TEXT, "Choose the file from which your concordance is to be generated.");
		screen.giveTextField("Title of the concordance:");
		screen.giveTextField("Description of the concordance:");
		screen.setTitleText("Compiler","This plug-in will allow you to generate a concordance from a text file.");;
	}

	public Map<String, Argument> getParameterList() {
		Map<String, Plugin.Argument> args = new HashMap<String, Plugin.Argument>();
		
		args.put("file", new Plugin.Argument(SelectionType.FileBrowser, 
											new Object[]{FileType.TEXT}, 
											"Choose the file from which your concordance is to be generated.", 
											null));
		args.put("concName", new Plugin.Argument(SelectionType.TextInput, null, "Title of the concordance:", null));
		args.put("concDesc", new Plugin.Argument(SelectionType.TextInput, null, "Description of the concordance:", null));
		
		return args;
	}

	public String getTitle() {
		return "Compiler"; 
	}
	
	public String getDescription(){
		return "This plug-in will allow you to generate a concordance from a text file.";
	}

	public void run(Map<String, Argument> args) {
		File inFile = (File) args.get("file").selectedValue;
		String concTitle = (String) args.get("concName").selectedValue;
		String concDesc = (String) args.get("concDesc").selectedValue;
		
		File baseConcDir = (File) args.get("baseConcDir").selectedValue;
		
		ConcordanceTool con = new ConcordanceTool(baseConcDir);
		
		con.compileConcordance(inFile, concTitle, concDesc);
		return;
	}

	public boolean requiresCompiledConcordances() {
		return false;
	}
}
